﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using ZF.BLL;
using System.Linq.Expressions;
using ZF.BLL.Linq;
using GCELibrary.Current;
namespace ZF.WS.house
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Search1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

           
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }
        protected void a(HttpContext context)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                int pz = 20;
                var sm = new SearchModel();


                List<Expression<Func<Model.H_House, bool>>> filterList = new List<Expression<Func<Model.H_House, bool>>>();
                IQueryable<Model.H_House> selector = dc.H_House;
                if (!string.IsNullOrEmpty(sm.area))
                    filterList.Add(p => p.AreaId1 == sm.area.Convert<int>());
                if (!string.IsNullOrEmpty(sm.dt))
                    filterList.Add(p => p.DealType == sm.dt.Convert<int>());
                if (!string.IsNullOrEmpty(sm.pmax))
                    filterList.Add(p => p.Price <= sm.pmax.Convert<int>());
                if (!string.IsNullOrEmpty(sm.pmin))
                    filterList.Add(p => p.Price >= sm.pmin.Convert<int>());
                if (!string.IsNullOrEmpty(sm.tin))
                    filterList.Add(p => p.HX_Tin == sm.tin.Convert<int>());
                if (!string.IsNullOrEmpty(sm.fan))
                    filterList.Add(p => p.HX_Fan == sm.fan.Convert<int>());
                foreach (var filter in filterList)
                {
                    selector = selector.Where(filter);
                }

                selector = selector.Where(p => p.Status == 1 && p.IsVerify);
                var iqPage = selector.OrderBy(p => p.HouseId)
                    .Skip(sm.pageIndex * pz).Take(pz);

                var source = iqPage.ToList().Select(p =>
                {

                    return new HoustModel()
                    {
                        City = SiteInfo.Instance.GetAreaOrDefault(p.AreaId1).Name,
                        Area = DictionaryConfig.HArea.DefaultIfEmpty(a => p.AreaId2.HasValue && a.AreaId == p.AreaId2.Value, new ZF.Model.Dic_Area()).Name,
                        Price = p.Price.ToString() + ((p.DealType == 1 || p.DealType == 2) ? "元/月" : "万元/套"),
                        From = p.Form == 1 ? "个人" : "中介",
                        Date = p.AddTime.ToShortDateString(),
                        Title = p.Title,
                        HouseId = p.HouseId,
                        DealType = SiteInfo.Instance.GetHouseDelt(p.DealType),
                        HouseModel = string.Format("{0}房{0}厅", p.HX_Fan, p.HX_Tin),
                        HouseType = p.HouseType,

                    };
                }).ToList();

                var str = Newtonsoft.Json.JsonConvert.SerializeObject(source);
                context.Response.Write(str);
                context.Response.End();


            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
